# Author : wyq
# 购物车实例
product_list = [
    ('iphone',5800),
    ('macPro',9800),
    ('bike',800),
    ('coffee',32),
    ('book',100)
]
shopping_list = []
salary = input("input you salary :")
if salary.isdigit():
    salary = int(salary)
    while True:
        for index,i in enumerate(product_list):
            print(index,i)
            # print(product_list.index(i))
        user_choic = input("select :")
        if user_choic.isdigit():
            user_choic = int(user_choic)
            if user_choic < len(product_list) and user_choic >= 0:
                p_item = product_list[user_choic]
                if p_item[1] <= salary:
                    shopping_list.append(p_item)
                    salary -= p_item[1]
                    print("added %s into shopping cart ,余额：%s:" % (p_item,salary))
                else:
                    print("\033[41;1m你的余额只剩[%s]啦\033[0m" % salary)
            else:
                print("product code [%s] is not exist !"% user_choic)
        elif user_choic == 'q':
            print("------------shop list-------------")
            for p in shopping_list:
                print(p)
            print("you current balance :",salary)
            exit()
        else:
            print("...")